package org.xiaojinlong.reading;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;
import java.util.logging.Logger;

/**
 * Created by jinlong on 2015/2/3.
 */
public class Race implements Iterable<String> {
    public static void main(String[] args) {
//       Integer[] ints = { 1, 2, 3, 4, 5, 6 };
//        List<Integer> list = new ArrayList<>();
//        Collections.addAll(list, ints);
//        list.forEach(System.out1::println);
//        List<Integer> another = Arrays.asList(ints);
//        another.add(3);
//        Set<String> set = new HashSet<>();
//        Collections.addAll(set, "a", "b", "a");
//        System.out1.println(set);
//        System.out1.println(set.contains("a"));
//        Set<String> anotherSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
//        Collections.addAll(anotherSet, "B", "A", "b", "C", "a");
//        System.out1.println(anotherSet);
//        String s1 = "Abc", s2 = "bBc";
//        int min = Math.min(s1.length(), s2.length());
//        for (int i=0; i<min; i++) {
//            char c1 = s1.charAt(i), c2 = s2.charAt(i);
//            if (c1 != c2) {
//                c1 = Character.toUpperCase(c1);
//                c2 = Character.toUpperCase(c2);
//                if (c1 != c2) {
//                    System.out1.println(c1-c2);
//                }
//            }
//        }
//        int[] bar = { 1, 2, 3, 4, 5 };
//        Arrays.asList(bar);
//        for (String s : new Race()) {
//            System.out1.println(s + " ");
//        }

//        for(MapTest.Entry entry: System.getenv().entrySet()) {
//            System.out1.println(entry.getKey() + ": " +
//                entry.getValue());
//        }
        try {
            throw new NullPointerException();
        } finally {
            return;
        }

    }
    private static Logger logger =
            Logger.getLogger("LoggingException");
    static void logException(Exception e) {
//        StringWriter trace = new StringWriter();
//        e.printStackTrace(new PrintWriter(trace));
//        e.printStackTrace(System.out1);
//        System.out1.println(e.getMessage());
//        logger.severe(trace.toString());
    }

    protected String[] words = ("And that is how " +
        "we know the Earth to be banana-shaped.").split(" ");
    @Override
    public Iterator<String> iterator() {
        return new Iterator<String>() {
            private int index = 0;
            @Override
            public boolean hasNext() {
                return index < words.length;
            }

            @Override
            public String next() {
                String next = words[index];
                index = index + 2;
                return next;
            }
        };
    }
}

class LoggingException extends Exception {
    private static Logger logger =
            Logger.getLogger("LoggingException");
    public LoggingException() {
        StringWriter trace = new StringWriter();
        printStackTrace(new PrintWriter(trace));
        logger.severe(trace.toString());
    }
}
